#pragma once
#include <string>
#include <vector>
#include <qbnet/sock/socket_proxy_common.h>
#include <QString>

struct ServerInfo
{
	int			index = 0;
	std::string address;
	int			port = 0;
};

struct ServerGroup
{
	int				index = 0;
	std::wstring	name;
	std::string		en_name;
	std::vector<ServerInfo>		servers;
};

struct LoginUserInfo
{
	std::string		strUser;		//用户名
	std::string		strPwd;			//密码
	int		lastServerGroupIndex=0;	//最近登录服务器组
	bool	savePwd = false;		//是否记住密码
	bool	autoRun = false;		//开机启动
};

class QuoteServerInfo
{
public:
	static QuoteServerInfo& instance();

	LoginUserInfo userInfo() const {
		return m_loginUserInfo;
	}
	ProxyInfo proxyInfo() const { return m_proxyInfo; }
	ServerInfo currentServer();
	void updateUserInfo(const LoginUserInfo&);
	void updateProxyInfo(const ProxyInfo&);
	void setCurrentServer(int g, int s) { m_currentGroup = g; m_currentServer = s; }

	const std::vector<ServerGroup>& serverGroups() const { return m_serverGroups; }
private:
	QuoteServerInfo();
	void loadConfig();
	void saveConfig();
	QString encryptPwd(const std::string&);
	std::string decryptPwd(const std::string&);
private:
	std::vector<ServerGroup> m_serverGroups;
	LoginUserInfo			 m_loginUserInfo;
	ProxyInfo				 m_proxyInfo;
	int						 m_currentGroup = 0;
	int						 m_currentServer = 0;
};